package com.zdx.yswl.view.dialog;

import com.zdx.yswl.R;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class LoadingProgressDialog extends Dialog {
	private static LoadingProgressDialog customProgressDialog = null;

	public LoadingProgressDialog(Context context, int theme) {
		super(context, theme);
	}

	public LoadingProgressDialog(Context context) {
		super(context);
	}

	public static LoadingProgressDialog createDialog(Context context) {
		customProgressDialog = new LoadingProgressDialog(context, R.style.LoadingProgressDialog);
		customProgressDialog.setContentView(R.layout.progress_dialog);
		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
		customProgressDialog.setCancelable(true);
		LinearLayout dialog_bg = (LinearLayout) customProgressDialog.findViewById(R.id.dialog_bg);
		dialog_bg.getBackground().setAlpha(150);
		return customProgressDialog;
	}

	public void onWindowFocusChanged(boolean hasFocus) {
		if (customProgressDialog == null) {
			return;
		}
		ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);
		AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
		animationDrawable.start();
	}

	/**
	 * 
	 * setTitile 标题
	 * 
	 */
	public LoadingProgressDialog setTitile(String strTitle) {
		return customProgressDialog;
	}

	/**
	 * 
	 * setMessage 提示内容
	 * 
	 */
	public LoadingProgressDialog setMessage(String strMessage) {
		TextView tvMsg = (TextView) customProgressDialog.findViewById(R.id.id_tv_loadingmsg);

		if (tvMsg != null) {
			tvMsg.setText(strMessage);
		}

		return customProgressDialog;
	}

}